﻿layui.use(['form', 'table', 'layer'], function () {
    var $ = layui.$,
        form = layui.form,
        table = layui.table,
        layer = layui.layer;

    //初始化文章表格
    var tableaccessory = table.render({
        elem: '#tableaccessory',
        url: '/Ashx/article.ashx', //数据接口
        method: 'post',
        where: { functionname: "findimg" },
        cols: [[ //表头 
            { field: 'fileurl', title: '预览', width: 130,  event: "showimg" },
            { field: 'filename', title: '名称' },
            { title: 'del', toolbar: "#barToDelete", width: 54 }

        ]]
    });


    table.on("tool(tableaccessory)", function (obj) {
        var data = obj.data;
        if (obj.event === "showimg") {//预览图片     
            var img = $(data.fileurl).attr("src");
            parent.layer.msg("<img src="+img+" style='width:100%;height:100%;'>", {
                area: ['100%', '100%']
            })  
        } else if (obj.event === "todelete") {
            var filepath = data.filepath;
            $.ajax({
                type: "post",
                url: "/Ashx/article.ashx",
                data: { functionname: "deleteimg", filepath: filepath },
                success: function (msg) {
                    if (msg == "true") {
                        parent.layer.msg("成功");
                        tableaccessory.reload();
                    } else {
                        parent.layer.msg("成功");
                        tableaccessory.reload();
                    }
                }
            });
        }
    });



})